package com.linwen.excise.leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName _1456定长子串中元音的最大数目
 * @Description TODO
 * @Author zero
 * @DATE 2024/10/7 9:06 PM
 * @Version 1.0
 */
public class _1456定长子串中元音的最大数目 {

    public static void main(String[] args) {
        _1456定长子串中元音的最大数目 inst = new _1456定长子串中元音的最大数目();
        String s = "abciiidef";
        int k = 3;
        System.out.println(inst.maxVowels(s,k));
    }
    public int maxVowels(String s, int k) {
        int ans = 0;
        int count = 0;
        for (int i = 0; i < k; i++) {
            count += yuanCount(s.charAt(i));
        }
        if(count==k){
            return k;
        }
        ans = count;
        for (int i = k; i < s.length(); i++) {
            count += yuanCount(s.charAt(i));
            count -= yuanCount(s.charAt(i - k));
            ans = Math.max(ans, count);
            if(count==k){
                return k;
            }
        }
        return ans;
    }
    private int yuanCount(char c) {
        return isYuan(c) ? 1 : 0;
    }

    private boolean isYuan(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
}
